<?php

namespace App\Jobs;

use App\Models\Sect;
use App\Models\SectMember;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SettlementSectPoint implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $userId, $point;
    public $tries = 5;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($userId, $point)
    {
        $this->userId = $userId;
        $this->point = $point;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $sectMember = SectMember::where('user_id', $this->userId)->first();
        if ($sectMember) {
            $sectId = $sectMember->sect_id;
            //查询门派,更新积分
            $sect = Sect::find($sectId);
            $sect->point = $sect->point + $this->point;
            $sect->save();
        }
    }
}
